package com.droowa.model.service;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.droowa.domain.Customer;
import com.droowa.domain.CustomerOut;
import com.droowa.domain.MileageOption;
import com.droowa.exception.DuplicatedIdException;
import com.droowa.model.dao.CustomerDAO;
import com.droowa.model.dao.MileageOptionDAO;

@Service
public class CustomerServiceImpl implements CustomerService {
	
	@Autowired
	private CustomerDAO dao;
	@Autowired
	private MileageOptionDAO mODao;
	
	@Override
	public Map getCustomerListPaging(int page) throws SQLException {
		// TODO 자동 생성된 메소드 스텁
		return null;
	}

	//가입처리
	@Override
	public int joinCustomer(Customer customer) throws SQLException,DuplicatedIdException{
		//가입일자customer에 설정
		customer.setJoinDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		MileageOption mo = mODao.selectMileageOption();
		System.out.println(mo);
		customer.setMileage(String.valueOf(mo.getJoinMileageOption()));
		//DB에 회원정보 등록 처리
		return dao.insertCustomer(customer);
	}
	
	@Override
	public Customer getCustomerById(String custId) throws SQLException, DuplicatedIdException {
		return dao.getCustomerById(custId);
	}
	
	//회원 정보 수정
	@Override
	public int modifyCustomer(Customer customer) throws SQLException{
		return dao.updateCustomer(customer);
	}
	
	//회원 탈퇴
	@Override
	public int removeCustomerById(String custId) throws SQLException {
		 return dao.deleteCustomerById(custId);
		
	}
	
	//탈퇴회원 테이블
	@Override
	public int insertRemoveCustomer(CustomerOut custOut) throws SQLException {
		custOut.setOutDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		return dao.insertRemoveCustomer(custOut);	
	}
	
	//탈퇴회원 조회
	@Override
	public CustomerOut getCustomerOutById(String custId) throws SQLException,DuplicatedIdException {
		return dao.getCustomerOutById(custId);
	}

	@Override
	public int deleteCustomerOutById(String custId) throws SQLException {
		return dao.deleteCustomerOutById(custId);
	}

	@Override
	public List<CustomerOut> getCustomerOutList() throws SQLException {
		return dao.selectCustomerOutList();
	}

	//전체 회원 목록 조회
	@Override
	public List<Customer> getCustomerList() throws SQLException{
		return dao.selectCustomerList();
	}
	
//######################### 관리자 회원관리 ###############################
	@Override//이름으로 조회
	public List<Customer> getCustomerListByName(String name) throws SQLException {
		return dao.selectCustomerListByName(name);
	}
	@Override//생년월일로 조회
	public List<Customer> getCustomerListByBirth(String birth) throws SQLException {
		return dao.selectCustomerListByBirth(birth);	
	}
	@Override//전화번호로 조회
	public List<Customer> getCustomerListByPhone(String phone)	throws SQLException {
		return dao.selectCustomerListByPhone(phone);
	}
	@Override//주소로 조회
	public List<Customer> getCustomerListByAddress(String address) throws SQLException {	
		return dao.selectCustomerListByAddress(address);
	}
	@Override//가입일로 조회
	public List<Customer> getCustomerListByJoinDate(String joinDate) throws SQLException {
		return dao.selectCustomerListByJoinDate(joinDate);
	}
	
	
	
	
	
	
	

}


















